package com.quatrix.openphantasy.client.datasource;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class LeagueDS extends BaseDS {
	final static String SERVICE_URL = GWT.getModuleBaseURL() + "/Proxy/LeagueService";
	
	///////////////////////////////////////////////////////////////////////////
	// Singleton setup
	///////////////////////////////////////////////////////////////////////////
	private static LeagueDS _instance;
	
	public static DataSource getInstance() {
		if (_instance == null) {
			_instance = new LeagueDS();
		}
		
		return _instance;
	}

	///////////////////////////////////////////////////////////////////////////
	// Fields
	///////////////////////////////////////////////////////////////////////////	
	private final DataSourceField _id = new DataSourceIntegerField("id");
	private final DataSourceField _name = new DataSourceTextField("name");
	private final DataSourceField _country = new DataSourceTextField("country");
	private final DataSourceField _level = new DataSourceIntegerField("level");
	private final DataSourceField _numOfTeams = new DataSourceIntegerField("numOfTeams");
	private final DataSourceField _numPromoted = new DataSourceIntegerField("numPromoted");
	private final DataSourceField _numRelegated = new DataSourceIntegerField("numRelegated");
	
	
	LeagueDS() {
		super("LeagueDS", SERVICE_URL);
		
		_id.setPrimaryKey(true);
		_id.setCanEdit(false);
		_country.setForeignKey("CountryDS.code");
		
		setFields(_id, _name, _country, _level, _numOfTeams, _numPromoted, _numRelegated);
	}
}
